<template>
    <div v-if="row.actions.length>2">
        <a @click="handleClickMore(row.actions[0].name, row)">{{ row.actions ? row.actions[0].label : '' }}</a>
        <Divider type="vertical" />
        <Dropdown @on-click="(name) => handleClickMore(name, row)" transfer>
            <a>更多
                <Icon type="ios-arrow-down" />
            </a>
            <DropdownMenu slot="list">
                <DropdownItem v-for="(item, i) in row.actions.slice(1)" :key="i" :name="item.name">{{ item.label }}
                </DropdownItem>
            </DropdownMenu>
        </Dropdown>
    </div>
    <div v-else>
        <a v-if="row.actions" @click="handleClickMore(row.actions[0].name, row)">{{ row.actions[0].label }}</a>
        <Divider v-if="row.actions && row.actions.length>1" type="vertical" />
        <a v-if="row.actions && row.actions.length>1" @click="handleClickMore(row.actions[1].name, row)">{{
            row.actions[1].label }}</a>
    </div>
</template>
<script>
    import { ApiRequest } from '@api/basePage';
    import dynamictableactions from '@/mixins/dynamictableactions'; // 混入通用代码
    export default {
        mixins: [
            dynamictableactions
        ],
        data () {
            return {
                actions: []
            }
        },
        methods: {
            handleClickMore (name, row) {
                if (name === 'Delete') {
                    this.$Modal.confirm({
                        title: '删除操作',
                        content: '确定删除此数据吗？',
                        onOk: () => {
                            let data = {
                                uuid: row.uuid
                            }
                            // 开始请求商品列表
                            ApiRequest(
                                this.requestApi.delTableList.url,
                                this.requestApi.delTableList.type,
                                data
                            ).then(res => {
                                this.$Message.success('删除成功')
                                this.actionsChange()
                            })
                        }
                    })
                } else if (name === 'View') {
                    this.$router.push({ path: '/commodity/commodityAccessManage/waitAccess/auditing/auditingView', query: { 'recordNo': row.recordNo } })
                } else if (name === 'AuditPass') {
                    let data = {
                    }
                    // 开始请求商品列表
                    ApiRequest(
                        this.requestApi.auditPassByRecord.url + '?recordNo=' + row.recordNo,
                        this.requestApi.auditPassByRecord.type,
                        data
                    ).then(res => {
                        if (res.retStatus == 1) {
                            this.$Message.success('审核成功')
                            this.actionsChange()
                        }
                    })
                } else if (name === 'AuditFail') {
                    let data = {
                    }
                    // 开始请求商品列表
                    ApiRequest(
                        this.requestApi.auditRecordFail.url + '?recordNo=' + row.recordNo,
                        this.requestApi.auditRecordFail.type,
                        data
                    ).then(res => {
                        if (res.retStatus == 1) {
                            this.$Message.success('审核成功')
                            this.actionsChange()
                        }
                    })
                } else {
                    let obj = {} // 动作的对象信息
                    row.actions.forEach(item => {
                        if (name === item.name) {
                            obj = item
                            return false
                        }
                    })
                    this.setTableRowData(row)
                    if (obj.handleType === 'link') {
                        // 操作类型为链接时，拼接参数跳转
                        if (obj.name === 'Edit') {
                            switch (row.commitType) {
                                case 'basicInfo':// 基础信息
                                    this.$router.push({ path: '/commodity/batchCommodityAdd/basicsInfoManage/basicsInfoManageList', query: { 'uuid': row.uuid } })
                                    break;
                                case 'manage':// 管理属性
                                    this.$router.push({ path: '/commodity/batchCommodityAdd/attInfoManage/attInfoManageList', query: { 'uuid': row.uuid } })
                                    break;
                                case 'package':// sku信息
                                    this.$router.push({ path: '/commodity/batchCommodityAdd/skuInfoManage/skuInfoManageList', query: { 'uuid': row.uuid } })
                                    break;
                                case 'supplyGoods':// 供货信息
                                    this.$router.push({ path: '/commodity/commodityAccessManage/waitAccess/gonghuoxinxi', query: { 'recordNo': row.recordNo, 'productUuid': row.uuid, } })
                                    break;
                                case 'salePrice':// 售价信息
                                    this.$router.push({ path: '/commodity/commodityAccessManage/waitAccess/xiaoshoujiage', query: { 'recordNo': row.recordNo, 'productUuid': row.uuid, } })
                                    break;
                                case 'pic':// 图文信息
                                    this.$router.push({ path: '/commodity/commodityAccessManage/waitAccess/tuwenjieshao', query: { 'recordNo': row.recordNo } })
                                    break;
                                case 'acceptance':// 验收标准
                                   this.$router.push({ path: '/commodity/commodityManage/acceptanceCriteriaManage/acceptanceCriteriaManageViewY', query: { 'recordNo': row.uuid } })
                                    break;
                                case 'qualification':// 资质信息
                                    this.$router.push({ path: '/commodity/commodityAccessManage/qualificationsManage/qualificationsManageEdit', query: { 'uuid': row.uuid } })
                                    break;
                            }
                        } else {
                            switch (row.commitType) {
                                case 'basicInfo':// 基础信息
                                    this.$router.push({ path: '/commodity/batchCommodityAdd/basicsInfoManage/basicsInfoManageList', query: { 'uuid': row.uuid } })
                                    break;
                                case 'manage':// 管理属性
                                    this.$router.push({ path: '/commodity/batchCommodityAdd/attInfoManage/attInfoManageList', query: { 'uuid': row.uuid } })
                                    break;
                                case 'package':// sku信息
                                    this.$router.push({ path: '/commodity/batchCommodityAdd/skuInfoManage/skuInfoManageList', query: { 'uuid': row.uuid } })
                                    break;
                                case 'supplyGoods':// 供货信息
                                    this.$router.push({ path: '/commodity/commodityAccessManage/waitAccess/gonghuoxinxi', query: { 'recordNo': row.recordNo, 'productUuid': row.uuid, 'hide': true } })
                                    break;
                                case 'salePrice':// 售价信息
                                    this.$router.push({ path: '/commodity/commodityAccessManage/waitAccess/xiaoshoujiage', query: { 'recordNo': row.recordNo, 'productUuid': row.uuid, 'hide': true } })
                                    break;
                                case 'pic':// 图文信息
                                    this.$router.push({ path: '/commodity/commodityAccessManage/waitAccess/tuwenjieshao', query: { 'recordNo': row.recordNo, 'hide': true } })
                                    break;
                                case 'acceptance':// 验收标准
                                      this.$router.push({ path: '/commodity/commodityManage/acceptanceCriteriaManage/acceptanceCriteriaManageViewY', query: { 'recordNo': row.uuid } })
                                    break;
                                case 'qualification':// 资质信息
                                    this.$router.push({ path: '/commodity/commodityAccessManage/qualificationsManage/qualificationsManageView', query: { 'uuid': row.uuid } })
                                    break;
                            }
                        }
                    }
                }
            }
        }
    }
</script>
